<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>通过递归获取指定类型的所有后代节点</title>
</head>
<body>
    <div>
        <span></span>
        <p>
            <a href="">
                <span></span>
            </a>
            <div>
                <section>
                    <span></span>
                </section>
            </div>
        </p>
    </div>
    <script>
        function getChildNodeByName(node,name){
            const nodes = [];
            [...node.childNodes].map(node => {
                if(node.tagName == name.toUpperCase()) nodes.push(node);
                nodes.push(...getChildNodeByName(node,name));
            });
            return nodes;
        }

        console.log(getChildNodeByName(document.body,'span'))
    </script>
</body>
</html>